package com.example.recyclerviewdemo.tree

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.entity.node.BaseNode
import com.example.recyclerviewdemo.R

class TreeActivity : AppCompatActivity() {


    private val teamTreeAdapter by lazy {
        NodeAdapter()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tree)
        title = TreeActivity::class.java.simpleName

        initRv()


    }

    private fun initRv() {
        val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
        recyclerView.run {
            layoutManager = LinearLayoutManager(this@TreeActivity)
            adapter = teamTreeAdapter
        }

        teamTreeAdapter.isUseEmpty = true

        //填充数据
        val mutableListOf = mutableListOf<BaseNode>()
        val child0 = mutableListOf<BaseNode>()
        val child1 = mutableListOf<BaseNode>()
        val child2 = mutableListOf<BaseNode>()

        val childNode0 = TreeNodeData("子标题0","子内容0",1,null)
        val childNode1 = TreeNodeData("子标题1","子内容1",1,null)
        child0.add(childNode0)
        child0.add(childNode1)
        mutableListOf.add(TreeNodeData("标题0","内容0",0,child0))

        val childNode2 = TreeNodeData("子标题2","子内容2",1,null)
        val childNode3 = TreeNodeData("子标题3","子内容3",1,null)
        child1.add(childNode2)
        child1.add(childNode3)
        mutableListOf.add(TreeNodeData("标题1","内容1",0,child1))

        val childNode4 = TreeNodeData("子标题4","子内容4",1,null)
        val childNode5 = TreeNodeData("子标题5","子内容5",1,null)
        child2.add(childNode4)
        child2.add(childNode5)
        mutableListOf.add(TreeNodeData("标题2","内容2",0,child2))

        teamTreeAdapter.data = mutableListOf
        teamTreeAdapter.notifyDataSetChanged()

    }
}